//
//  FPSelectRoleViewController.m
//  ForestPack
//
//  Created by jimmy on 2018/7/4.
//  Copyright © 2018年 郑洲. All rights reserved.

///  选择身份的界面

#import "FPSelectRoleViewController.h"
#import "UIView+Utils.h"
#import "FPReviewViewController.h"
//#import "FPPesonRegisViewController.h"

@interface FPSelectRoleViewController ()

@property (nonatomic,strong)  FPSelectRoleView *designerView;
@property (nonatomic,strong)  FPSelectRoleView *managerView;
@property (nonatomic,strong)  FPSelectRoleView *customerView;


@end

@implementation FPSelectRoleViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = NO;
    [self.navigationController.navigationBar setBackgroundImage:[self createImageWithColor:RGB_COLOR(237, 34, 59)] forBarMetrics:UIBarMetricsDefault];
}

- (UIImage *)createImageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"角色选择"];
    
    [self setViewUI];
    
}

-(void)sureClick:(FinalRegisterType)finalRegType
{
    //选择完注册的身份后要将上个页面的信息传给下个界面
    FPReviewViewController *vc = [[FPReviewViewController alloc] init];
    vc.registerType = self.registerType;
    vc.enterpriseNameStr = self.enterpriseNameStr;
    vc.enterpriseImageUrl = self.enterpriseImageUrl;
    vc.passwordNum = self.passwordNum;
    vc.finalRegType = finalRegType;
    [self.navigationController pushViewController:vc animated:true];
}

//-(void)getData:(FinalRegisterType)finalRegType
//{
//    NSString *url = [NSString stringWithFormat:@"%@app/app_company_register",REQUESTHEADER];//企业用户注册
//    NSDictionary * parameter = @{@"customer_type":@(finalRegType)};
//    [HttpManager postHttpRequestByPost:url andParameter:parameter success:^(id successResponse) {
//        NSString *status = [NSString stringWithFormat:@"%@",successResponse[@"status"]];
//        if ([status isEqualToString:@"1"]) {
//            kNSUDefaultSaveVauleAndKey(successResponse[@"token"], @"token");
//            FPPesonRegisViewController *regisVC = [[FPPesonRegisViewController alloc] init];
//            regisVC.registerType = InitRegisterType_Enterprise;
//            regisVC.finalRegType = finalRegType;
//            [self.navigationController pushViewController:regisVC animated:true];
//        }else{
//            [HttpManager showNoteMsg:[NSString stringWithFormat:@"%@",successResponse[@"msg"]]];
//        }
//    } andFailure:^(id failureResponse) {
//        [HttpManager showFail];
//    }];
//}

-(void)setViewUI
{
    self.designerView = [[FPSelectRoleView alloc] init];
    self.designerView.finalRegType = FinalRegisterType_Designer;
    self.designerView.frame = CGRectMake(0, 20, SCREEN_WIDTH, 105);
    self.designerView.headImageView.image = [UIImage imageNamed:@"设计师"];
    self.designerView.nameLabel.text = @"设计师";
    WeakObj(self);
    self.designerView.finalViewSelectBlock = ^{
        [selfWeak sureClick:FinalRegisterType_Designer];
    };
    [self.view addSubview:self.designerView];
    
    self.managerView = [[FPSelectRoleView alloc] init];
    self.managerView.finalRegType = FinalRegisterType_Manerger;
    self.managerView.frame = CGRectMake(0, self.designerView.bottom , SCREEN_WIDTH, 105);
    self.managerView.headImageView.image = [UIImage imageNamed:@"包装经理人"];
    self.managerView.nameLabel.text = @"包装经理人";
    self.managerView.finalViewSelectBlock = ^{
        [selfWeak sureClick:FinalRegisterType_Manerger];
    };
    [self.view addSubview:self.managerView];

    
    self.customerView = [[FPSelectRoleView alloc] init];
    self.customerView.finalRegType = FinalRegisterType_Customer;
    self.customerView.frame = CGRectMake(0, self.managerView.bottom , SCREEN_WIDTH, 105);
    self.customerView.headImageView.image = [UIImage imageNamed:@"终端客户"];
    self.customerView.nameLabel.text = @"终端客户";
    self.customerView.finalViewSelectBlock = ^{
        [selfWeak sureClick:FinalRegisterType_Customer];
    };
    [self.view addSubview:self.customerView];
 
    
}

@end


@interface FPSelectRoleView ()

//@property (nonatomic,strong)  UIImageView  * headImageView;
@property (nonatomic,strong)  UIImageView  * rightImageView;
//@property (nonatomic,strong)  UILabel      * nameLabel;

@end

@implementation FPSelectRoleView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self setViewUI];
    }
    return self;
}


-(void)registClick
{
    if (self.finalViewSelectBlock) {
        self.finalViewSelectBlock();
    }
}

-(void)setViewUI
{
    UIView *bjView = [[UIView alloc] init];
    bjView.frame = CGRectMake(40, 10, SCREEN_WIDTH - 80, 85);
    bjView.backgroundColor = RGB_COLOR(238, 238, 238);
    bjView.userInteractionEnabled = true;
    [self addSubview:bjView];
    
    self.headImageView = [[UIImageView alloc] init];
    self.headImageView.frame = CGRectMake(23, bjView.top + 5, 54, 67);
    [bjView addSubview:self.headImageView];
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.frame = CGRectMake(self.headImageView.right + 13, bjView.top + 24, 120, 20);
    self.nameLabel.font = [UIFont systemFontOfSize:18];
    self.nameLabel.textColor = RGB_COLOR(51, 51, 51);
    [bjView addSubview:self.nameLabel];
    
    UIImageView *rightImageView = [[UIImageView alloc] init];
    rightImageView.frame = CGRectMake(bjView.width - 25, bjView.top + 25, 13, 22);
    rightImageView.image = [UIImage imageNamed:@"灰色"];
    [bjView addSubview:rightImageView];
    
    UIButton *bjButton = [UIButton buttonWithType:UIButtonTypeCustom];
    bjButton.frame = CGRectMake(0, 0, bjView.width, bjView.height);
    bjButton.backgroundColor = [UIColor clearColor];
    [bjButton addTarget:self action:@selector(registClick) forControlEvents:UIControlEventTouchUpInside];
    [bjView addSubview:bjButton];
    
}


@end
